#include <nice2d/piece/piece.h>

IMPLEMENT_OBJECT(Piece, Sprite)

class PieceData
{
public:
    sf::String name;
    sf::String description;
    bool configurated = false;
    bool selected = false;
    std::string icon;
};

Piece::Piece(const sf::String &name):
    data(new PieceData())
{
    data->name = name;
}

Piece::~Piece()
{
}

void Piece::setName(const sf::String &name)
{
    data->name = name;
}

sf::String Piece::getName() const
{
    return data->name;
}

void Piece::setDescription(const sf::String &description)
{
    data->description = description;
}

sf::String Piece::getDescription() const
{
    return data->description;
}

void Piece::configurate()
{
    data->configurated = true;
}

bool Piece::isConfigurated() const
{
    return data->configurated;
}

void Piece::setPieceIcon(const std::string &file)
{
    data->icon = file;
}

std::string Piece::getPieceIcon()
{
    return data->icon;
}

void Piece::select()
{
    if (!data->selected) {
        data->selected = true;
        onSelected(as<Piece>());
    }
}

void Piece::unselect()
{
    if (data->selected) {
        data->selected = false;
        onUnselected(as<Piece>());
    }
}

bool Piece::isSelected() const
{
    return data->selected;
}

PTree Piece::serialize()
{
    PTree node;
    SERIALIZE_BASE_OBJECT(node, Sprite)
    node.add("name", data->name.toAnsiString());
    node.add("description", data->description.toAnsiString());
    node.add("configurate", data->configurated);
    node.add("icon", data->icon);
    node.add("selected", data->selected);
    node.add("icon", data->icon);
    return node;
}

void Piece::deserialize(const PTree &node)
{
    //TODO
}
